# Create your views here.
from django.http import HttpResponse
from django.http import Http404
from datetime import datetime
#json generator import
from nekoTrace.nekonekotrace.jsonGenerator import *

def hello(request):
    return HttpResponse("Hello world")

#------------------------------------------------
#Cat Info view
#------------------------------------------------
def catInfoView(request, catId):
    try:
        catId = int(catId)
    except ValueError:
        raise Http404()
    return HttpResponse(catInfoGenerator(catId))

def catInfoAllView(request):
    return HttpResponse(catInfoAllGenerator())


#--------------------------------------------------
# location view
#--------------------------------------------------

def locationListView(request):
    return HttpResponse(locationList())

def locationInfoView(request, lId):
    try:
        lId = int(lId)
    except ValueError:
        raise Http404()
    return HttpResponse(locationInfoGenerator(lId))

def locationInfoByCatView(request, catid):
    try:
        catid = int(catid)
    except ValueError:
        raise Http404()
    return HttpResponse(locationInfoByCatGenerator(catid))

def locationInfoAllView(request):
    return HttpResponse(locationInfoAllGenerator())

#--------------------------------------------------
#treat
#--------------------------------------------------

def catTreatByUserView(request, userId):
    try:
        userId = int(userId)
    except ValueError:
        raise Http404()
    return HttpResponse(catTreatByUserGenerator(userId))

def catTreatAllView(request):
    return HttpResponse(catTreatAllGenerator())

#--------------------------------------------------
# impression view
#--------------------------------------------------
def catImpressionByCatView(request, catId):
    try:
        catId = int(catId)
    except ValueError:
        raise Http404()
    return HttpResponse(catImpressionByCatGenerator(catId))

def catImpressionByUserView(request, userId):
    try:
        userId = int(userId)
    except ValueError:
        raise Http404()
    return HttpResponse(catImpressionByUserGenerator(userId))

def catImpressionAllView(request):
    return HttpResponse(catImpressionAllGenerator())

#---------------------------------------------------
# treat view
#---------------------------------------------------
def catTreatByCatView(request, catId):
    try:
        catId = int(catId)
    except ValueError:
        raise Http404()
    return HttpResponse(catTreatByCatGenerator(catId))

#--------------------------------------------------------------
#album view
#--------------------------------------------------------------
def catAlbumByCatView(request, catId):
    try:
        catId = int(catId)
    except ValueError:
        raise Http404()
    return HttpResponse(catAlbumByCatGenerator(catId))

def catAlbumByUserView(request, userId):
    try:
        userId = int(userId)
    except ValueError:
        raise Http404()
    return HttpResponse(catAlbumByUserGenerator(userId))

def catAlbumListView(request):
    return HttpResponse(catAlbumListGenerator())

#--------------------------------------------------
# saying view
#--------------------------------------------------

def sayingByIDView(request, sId):
    try:
        sId = int(sId)
    except ValueError:
        raise Http404()
    return HttpResponse(sayingByIDGenerator(sId))

def sayingByCatView(request, cId):
    try:
        cId = int(cId)
    except ValueError:
        raise Http404()
    return HttpResponse(sayingByCatGenerator(cId))

#-------------------------------------------------
# news view
#-------------------------------------------------
def newslistByCatView(request, catId):
    try:
        catId = int(catId)
    except ValueError:
        raise Http404()
    return HttpResponse(newslistByCatGenerator(catId))

def newslistAllView(request):
    return HttpResponse(newslistAllGenerator())

def newsByIDView(request, nId):
    try:
        nId = int(nId)
    except ValueError:
        raise Http404()
    return HttpResponse(newsByIDGenerator(nId))

def newslistSinceByCatView(request, time, catid):
    try:
        catid = int(catid) 
        time = datetime.strptime(time, '%Y-%m-%d %H:%M:%S')
    except ValueError:
        raise Http404()
    return HttpResponse(newslistSinceByCatGenerator(time, catid))

def newslistSinceAllView(request, time):
    try:
        time = datetime.strptime(time, '%Y-%m-%d %H:%M:%S')
    except ValueError:
        raise Http404()
    return HttpResponse(newslistSinceAllGenerator(time))